import cv2
from picamera2 import Picamera2
from datetime import datetime

def main():
    picam2 = Picamera2()
    config = picam2.create_still_configuration(
            main={"size": (640, 480)},
            controls={"FrameRate": 30}
        )
    picam2.configure(config)
    picam2.start()
    print(f"Camera started at {datetime.now()}")

    count = 0

    while True:
        frame = picam2.capture_array()
        count += 1
        print(f"Captured frame {count} at {datetime.now()}")

        if cv2.waitKey(1) & 0xFF == ord("q"):
            break

    picam2.stop()
    print("Camera stopped.")

if __name__ == "__main__":
    main()